﻿using GoodDotNet.IService;
using GoodDotNet.Core.Entity;
using GoodDotNet.Core.Model;
using NetCoreClass;
using GoodDotNet.Core.Data;

namespace GoodDotNet.Service
{
    public class AdminRoleService : BaseService, AdminRoleIService
    {
        public AdminRoleService(UnitOfWork _unitOfWork) : base(_unitOfWork)
        {
        }

        public void Add(ParInsertAdminRoleModel pars,int uid,int site)
        {
            AdminRole entity = new AdminRole();

            entity.RoleName = pars.role_name;

            entity.Description = pars.description;

            entity.Uid = uid;

            entity.Grade = pars.grade;
            entity.InsertTime = DateTime.Now;
            entity.Site = site;


            _unitOfWork.AdminRoleRepository.Add(entity);
            _unitOfWork.SaveChanges();

        }

        /// <summary>
        /// 编辑角色
        /// </summary>
        /// <param name="id">角色id</param>
        /// <param name="RoleName">角色名称</param>
        /// <param name="Description">角色说明</param>
        /// <param name="uid">用户id</param>
        /// <returns></returns>

        public int Update(int id, string RoleName, string Description, int uid)
        {
            textClear tc = new textClear();
            RoleName = tc.cutBadStr(RoleName);
            Description = tc.cutBadStr(Description);
            System.FormattableString sql = $"update  admin_role set role_name={RoleName},description={Description},uid={uid}  where  Id={id}";
            return _unitOfWork.AdminRoleRepository.ExecuteSql(sql);

        }



        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="pars"></param>
        /// <returns></returns>

        public int Delete(ParDeleteAdminRoleModel pars)
        {
            System.FormattableString sql = $"delete from admin_role where  Id={pars.Id}";
            return _unitOfWork.AdminRoleRepository.ExecuteSql(sql);
        }

        /// <summary>
        /// 站点list
        /// </summary>
        /// <param name="site">站点id</param>
        /// <returns></returns>
        public List<AdminRole> GetList()
        {
            var roles = _unitOfWork.AdminRoleRepository.GetList();
            return roles;
        }
        
       
    }
}
